import { defineBuildConfig } from 'unbuild';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import postcss from 'rollup-plugin-postcss';
import typescript from 'rollup-plugin-typescript2';

export default defineBuildConfig({
  entries: ['src/index'],
  failOnWarn: false,
  declaration: false,
  clean: true,
  rollup: {
    emitCJS: false,
    dts: {
      tsconfig: 'tsconfig.build.json',
    },
  },
  hooks: {
    'rollup:options'(_ctx, options) {
      options.plugins = [
        vue(),
        vueJsx(),
        postcss({
          extract: 'style.css',
          minimize: true,
          use: ['sass'], // 使用 sass 处理 scss 文件
          parser: 'postcss-scss', // 告诉 PostCSS 使用 SCSS 解析器
        }),
        typescript({
          check: false,
          tsconfigOverride: {
            compilerOptions: {
              declaration: true,
              declarationDir: 'dist/types',
            },
            exclude: ['**/__tests__', '**/*.test.ts'],
          },
          useTsconfigDeclarationDir: true,
        }),
        ...(options.plugins || []),
      ];
    },
  },
});
